﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：李弼翀
    //
    // 文件名：HospitalAccessAuthorize.aspx.cs
    // 文件功能描述：根据搜索条件找出满足条件的医疗机构信息，并决定选中的医疗机构是否可以入围
    // 创建标识：李弼翀 2009-03-16
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Query;

using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.Model;

namespace HZ.DrugTrade.Web.Admin
{
    public partial class AreaAccessPrice : BasePage
    {

        IBLL_OperatingRule operateRuleCtrl = Factory.BLL_OperatingRule();
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        public AreaAccessPrice()
        {
            this.ModuleNo = Module.采购产品管理.ToString();
            this.PageOperateType = OperateType.盟市招标机构授权.ToString();
        }
        /// <summary>
        /// 目录入围权限ID
        /// </summary>
        protected string _operatingRuleID = "";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                //查询
                setBind();
            }
        }

        /// <summary>
        /// 定义绑定数据的方法
        /// </summary>
        private void setBind()
        {
            try
            {
                DataTable mhrList = ipb.GetAreaAccessPrice();
                gvwHospitalList.DataSource = mhrList;
                gvwHospitalList.DataBind();
            }
            catch (Exception ex)
            {
                PageError("数据连接失败！" + ex.Message, "");
            }
        }

        public bool BindCatalogType(object obj, string p)
        {
            string[] str = obj.ToString().Split('|');
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == p) return true;
            }
            return false;
        }

        public bool BindCatalogState(object obj, string p)
        {
            string str = obj.ToString();
            if (str == p)
            {
                return true;
            }
            else
            {
                return false;
            }
        }



        #region 获取地区信息
        /// <summary>
        /// 获取地区查询条件 AreaID
        /// </summary>
        /// <returns></returns>
        private string GetAreaID()
        {
            string areaId = "";

            //首次进入使用当前用户所在区域ID
            areaId = CurrentAccount.GetUser().Org.Area.AreaID;

            //优先获取区县，其次城市，再次省份
            if (new Common.ConvertHelper(Request.Form["ctl00$ContentPlaceHolder1$ddlCountry"]).String != Constants.ALL_ITEM_VALUE)
            {
                areaId = Request.Form["ctl00$ContentPlaceHolder1$ddlCountry"];
            }
            else
            {
                if (new Common.ConvertHelper(Request.Form["ctl00$ContentPlaceHolder1$ddlCity"]).String != Constants.ALL_ITEM_VALUE)
                {
                    areaId = Request.Form["ctl00$ContentPlaceHolder1$ddlCity"];
                }
                else if (new Common.ConvertHelper(Request.Form["ctl00$ContentPlaceHolder1$ddlProvice"]).String != Constants.ALL_ITEM_VALUE)
                {
                    areaId = Request.Form["ctl00$ContentPlaceHolder1$ddlProvice"];
                }

            }
            return areaId;
        }
        #endregion



        protected void btnDisableAccess_Click(object sender, EventArgs e)
        {
           
            //保存目录权限数据
            string catalogtype = "";
            List<ManageOrg> moList = new List<ManageOrg>();

            for (int i = 0; i < gvwHospitalList.Rows.Count; i++)
            {
                ManageOrg mo = new ManageOrg();
                catalogtype = "";

                CheckBox c3 = (CheckBox)gvwHospitalList.Rows[i].Cells[3].FindControl("ck3");//可修改

                if (catalogtype != "")
                {
                    if (catalogtype.Substring(catalogtype.Length - 1, 1) == "|")
                    {
                        catalogtype = catalogtype.Substring(0, catalogtype.Length - 1);
                    }
                    mo.CatalogType = catalogtype;
                }
                else
                {
                    mo.CatalogType = "";
                }
                if (c3.Checked)
                {
                    mo.CatalogState = 1;
                }
                else
                {
                    mo.CatalogState = 0;
                }
                mo.ManageOrgID = Convert.ToString(gvwHospitalList.DataKeys[i].Value);
                moList.Add(mo);
                
            }
            int result = ipb.ValidateAreaAccessPrice(moList);
            if (result != 1)
            {
                HZ.Web.WebUtil.Alert("更新失败！", this);
                return;
            }

            PageInfo("保存成功", this.ReturnUrl);
            setBind();
        }

       
    }
}
